<?php
if($_POST['edititem'] && $_POST['edititem']!=''){
	$item = $_POST['edititem'];
}
?>
<h2>Edit <?php echo ucwords($item); ?></h2>
<br /><br />
<?php 
if($_POST['submitaddress'] && $_POST['submitaddress']!=""){
	$address = $_POST['address'];
	$address2 = $_POST['address2'];
	$city = $_POST['city'];
	$state = $_POST['state'];
	$zip = $_POST['zip'];
	$hours = $_POST['hours'];
	$siteid = $site['id'];
	$keyvalues = array("address='$address'","address2='$address2'","city='$city'","state='$state'","zip='$zip'","hours='$hours'");
	dbUpdate('sites',$keyvalues,array("id=$siteid"));
	$siteqry = dbSelect('sites',array("id=$siteid"));
	if(mysql_numrows($siteqry) > 0){
		$site = mysql_fetch_array($siteqry);
	}
}
if($_POST['submitcontact'] && $_POST['submitcontact']!=""){
	$phone = $_POST['phone'];
	$fax = $_POST['fax'];
	$email = $_POST['email'];
	$website = $_POST['website'];
	$siteid = $site['id'];
	$keyvalues = array("phone='$phone'","fax='$fax'","email='$email'"," website='$website'");
	dbUpdate('sites',$keyvalues,array("id=$siteid"));
	$siteqry = dbSelect('sites',array("id=$siteid"));
	if(mysql_numrows($siteqry) > 0){
		$site = mysql_fetch_array($siteqry);
	}
}
if($_POST['submititem'] && $_POST['submititem']!=""){
	$item = $_POST['item'];
	//echo '<br />'.$item;
	$edititem = $_POST['edititem'];
	//echo '<br />'.$edititem;
	$siteid = $site['id'];
	dbUpdate('sites',array("$item='$edititem'"),array("id=$siteid"));
	$siteqry = dbSelect('sites',array("id=$siteid"));
	if(mysql_numrows($siteqry) > 0){
		$site = mysql_fetch_array($siteqry);
	}
	echo '<script type="text/javascript">window.location.href=\''.$thisroot.'\';</script>';
}
 ?>
	<?php if($item=='address'){ ?>
		<form name="editaddressform" action="<?php echo $thisroot; ?>/edit.php" method="post" autocomplete="off">
			<div align="center" width="600">
				<table>
					<tr><td class="inputlabel">Address: </td><td><input type="text" name="address" size="30" value="<?php echo urldecode($site['address']); ?>" /></td></tr>
					<tr><td class="inputlabel">Address2: </td><td><input type="text" name="address2" size="30" value="<?php echo urldecode($site['address2']); ?>" /></td></tr>
					<tr><td class="inputlabel">City: </td><td><input type="text" name="city" size="30" value="<?php echo urldecode($site['city']); ?>" /></td></tr>
					<tr><td class="inputlabel">State: </td><td><input type="text" name="state" size="30" value="<?php echo urldecode($site['state']); ?>" /></td></tr>
					<tr><td class="inputlabel">Zip: </td><td><input type="text" name="zip" size="30" value="<?php echo urldecode($site['zip']); ?>" /></td></tr>
					<tr><td class="inputlabel">Hours: </td><td><input type="text" name="hours" size="30" value="<?php echo urldecode($site['hours']); ?>" /></td></tr>
					<tr><td>&nbsp;</td><td><input type="submit" name="submitaddress" value="Save" /></td></tr>
				</table>
			</div>
			<input type="hidden" name="edititem" size="30" value="<?php echo $edititem; ?>" />
		</form>
	<?php 
		}elseif($item=='contact'){ 
	?>
		<form name="editcontactform" action="<?php echo $thisroot; ?>/edit.php" method="post" autocomplete="off">
			<div align="center" width="600">
				<table>
					<tr><td class="inputlabel">Phone: </td><td><input type="text" name="phone" size="30" value="<?php echo urldecode($site['phone']); ?>" /></td></tr>
					<tr><td class="inputlabel">Fax: </td><td><input type="text" name="fax" size="30" value="<?php echo urldecode($site['fax']); ?>" /></td></tr>
					<tr><td class="inputlabel">Email: </td><td><input type="text" name="email" size="30" value="<?php echo urldecode($site['email']); ?>" /></td></tr>
					<tr><td class="inputlabel">Website: </td><td><input type="text" name="website" size="30" value="<?php echo urldecode($site['website']); ?>" /></td></tr>
					<tr><td>&nbsp;</td><td><input type="submit" name="submitcontact" value="Save" /></td></tr>
				</table>
			</div>
			<input type="hidden" name="edititem" size="30" value="<?php echo $edititem; ?>" />
		</form>
	<?php 
		}else{ ?>
		<form name="edittextform" action="<?php echo $thisroot; ?>/edit.php" method="post" autocomplete="off">
			<div align="center" width="600">
				<table>
					<tr>
						<td class="inputlabel">Edit <?php echo ucwords($item); ?>&nbsp;</td>
						<td>
						<input type="text" name="edititem" size="30" value="<?php echo $site[$item]; ?>" />
						<input type="hidden" name="item" size="30" value="<?php echo $item; ?>" />
						</td>
					</tr>
					<tr><td>&nbsp;</td><td><input type="submit" name="submititem" value="Save & Return" /></td></tr>
				</table>
			</div>
		</form>
	<?php 
	} 
	?>
